<?php
declare(strict_types=1);

use Phinx\Migration\AbstractMigration;

final class CreateLibraryViewTable extends AbstractMigration
{
    public function up()
    {

        $this->table('task_library_view_config', ['id' => false, 'primary_key' => ['id'], 'engine' => 'InnoDB', 'collation' => 'utf8mb4_general_ci', 'comment' => '任务库视图'])
            ->addColumn('id', 'integer', ['identity' => true, 'signed' => false, 'limit' => 11, 'comment' => '主键ID'])
            ->addColumn('name', 'string', ['default' => '', 'limit' => 128, 'comment' => '视图名称'])
            ->addColumn('type', 'string', ['default' => '', 'limit' => 128, 'comment' => '视图类型'])
            ->addColumn('module_code', 'string', ['null' => false, 'default' => '', 'limit' => 20, 'comment' => '关联模块 (asset 资产 shot 镜头)'])
            ->addColumn('user_id', 'integer', ['signed' => false, 'default' => 0, 'limit' => 11, 'comment' => '用户id'])
            ->addColumn('config', 'json', ['null' => true, 'comment' => '配置设置'])
            ->addColumn('project_id', 'integer', ['signed' => false, 'default' => 0, 'limit' => 11, 'comment' => '项目ID'])
            ->addColumn('created', 'integer', ['null' => false, 'default' => 0, 'limit' => 11, 'signed' => false, 'comment' => '创建时间'])
            ->addColumn('created_by', 'integer', ['null' => false, 'default' => 0, 'limit' => 11, 'signed' => false, 'comment' => '创建人'])
            ->addColumn('updated', 'integer', ['null' => false, 'default' => 0, 'limit' => 11, 'signed' => false, 'comment' => '更新时间'])
            ->addColumn('updated_by', 'integer', ['null' => false, 'default' => 0, 'limit' => 11, 'signed' => false, 'comment' => '更新人'])
            ->addColumn('sort_index', 'integer', ['default' => 0, 'limit' => 11, 'comment' => '排序'])
            ->addIndex(['user_id'], ['type' => 'normal', 'name' => 'idx_user_id'])
            ->save();
    }

    public function down()
    {
        $this->table('library_view_config')->drop()->save();
    }
}
